package com.itfreer.power.dao.useredit;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import com.itfreer.form.api.JdbcBaseEntity;
import com.itfreer.power.entity.useredit.UserEditApplyEntity;
import com.itfreer.power.entity.useredit.UserEditApplyItemEntity;

/**
 * 用户修改申请信息表
 */
@Entity(name = "sso_user_edit")
@Table(indexes = { @Index(name = "s_u_e_applyUserId", columnList = "s_applyUserId") })
public class JdbcUserEditApplyEntity implements JdbcBaseEntity<UserEditApplyEntity>, Serializable {

	private static final long serialVersionUID = -1522478556148407234L;

	/**
	 * 申请ID
	 */
	@Id
	@Column(name = "id", length = 50, nullable = false)
	private String applyID;
	
	/**
	 * 申请标题
	 */
	@Column(name = "s_name", length = 50, nullable = true)
	private String applyName;
	
	/**
	 * 申请人ID
	 */
	@Column(name = "s_applyUserId", length = 50, nullable = true)
	private String applyUserId;
	
	/**
	 * 申请人名称
	 */
	@Column(name = "s_applyUserName", length = 50, nullable = true)
	private String applyUserName;
	
	/**
	 * 申请人时间
	 */
	@Column(name = "d_applyDate", length = 50, nullable = true)
	private Date applyDate;
	
	/**
	 * 申请人所在机构
	 */
	@Column(name = "s_organizationId", length = 50, nullable = true)
	private String organizationId;
	
	/**
	 * 申请说明
	 */
	@Column(name = "s_applyInfo", length = 500, nullable = true)
	private String applyInfo;
	
	/**
	 * 申请附件
	 */
	@Column(name = "s_applyFile", length = 200, nullable = true)
	private String applyFile;
	
	/**
	 * 申请状态
	 */
	@Column(name = "s_state", length = 50, nullable = true)
	private String state;
	
	/**
	 * 审批用户ID
	 */
	@Column(name = "s_examineUserId", length = 50, nullable = true)
	private String examineUserId;
	
	/**
	 * 审批用户名称
	 */
	@Column(name = "s_examineUserName", length = 50, nullable = true)
	private String examineUserName;
	
	/**
	 * 审批用户时间
	 */
	@Column(name = "d_examineDate", length = 50, nullable = true)
	private Date examineDate;
	
	/**
	 * 审批信息
	 */
	@Column(name = "s_examineInfo", length = 500, nullable = true)
	private String examineInfo;
	
	/**
	 *子表对象
	 * @return
	 */
	@SuppressWarnings("deprecation")
	@org.hibernate.annotations.ForeignKey(name = "none")
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "s_applyID")
	@OrderBy("id ASC")
	private Set<JdbcUserEditApplyItemEntity> items = new HashSet<JdbcUserEditApplyItemEntity>();
	
	
	/**
	 * 子表对象
	 * @return
	 */
	public Set<JdbcUserEditApplyItemEntity> getItems() {
		return items;
	}

	/**
	 * 子表对象
	 * @param items
	 */
	public void setItems(Set<JdbcUserEditApplyItemEntity> items) {
		this.items = items;
	}

	public String getApplyID() {
		return applyID;
	}

	public void setApplyID(String applyID) {
		this.applyID = applyID;
	}

	public String getApplyName() {
		return applyName;
	}

	public void setApplyName(String applyName) {
		this.applyName = applyName;
	}

	public String getApplyUserId() {
		return applyUserId;
	}

	public void setApplyUserId(String applyUserId) {
		this.applyUserId = applyUserId;
	}

	public String getApplyUserName() {
		return applyUserName;
	}

	public void setApplyUserName(String applyUserName) {
		this.applyUserName = applyUserName;
	}

	public Date getApplyDate() {
		return applyDate;
	}

	public void setApplyDate(Date applyDate) {
		this.applyDate = applyDate;
	}

	public String getOrganizationId() {
		return organizationId;
	}

	public void setOrganizationId(String organizationId) {
		this.organizationId = organizationId;
	}

	public String getApplyInfo() {
		return applyInfo;
	}

	public void setApplyInfo(String applyInfo) {
		this.applyInfo = applyInfo;
	}

	public String getApplyFile() {
		return applyFile;
	}

	public void setApplyFile(String applyFile) {
		this.applyFile = applyFile;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getExamineUserId() {
		return examineUserId;
	}

	public void setExamineUserId(String examineUserId) {
		this.examineUserId = examineUserId;
	}

	public String getExamineUserName() {
		return examineUserName;
	}

	public void setExamineUserName(String examineUserName) {
		this.examineUserName = examineUserName;
	}

	public Date getExamineDate() {
		return examineDate;
	}

	public void setExamineDate(Date examineDate) {
		this.examineDate = examineDate;
	}

	public String getExamineInfo() {
		return examineInfo;
	}

	public void setExamineInfo(String examineInfo) {
		this.examineInfo = examineInfo;
	}
	
	@Override
	public void from(UserEditApplyEntity entity) {
		BeanUtils.copyProperties(entity, this, "items");
		Set<JdbcUserEditApplyItemEntity> items = new HashSet<JdbcUserEditApplyItemEntity>();
		Set<UserEditApplyItemEntity> entityItems = entity.getItems();
		if(entityItems!=null) {
			for (UserEditApplyItemEntity item : entityItems) {
				JdbcUserEditApplyItemEntity jItem = new JdbcUserEditApplyItemEntity();
				jItem.from(item);
				items.add(jItem);
			}
		}
		this.setItems(items);
	}

	@Override
	public UserEditApplyEntity toEntity() {
		UserEditApplyEntity toEntity = new UserEditApplyEntity();
		BeanUtils.copyProperties(this, toEntity,"items");
		
		Set<UserEditApplyItemEntity> items = new HashSet<UserEditApplyItemEntity>();
		Set<JdbcUserEditApplyItemEntity> entityItems = this.getItems();
		if(entityItems != null) {
			for (JdbcUserEditApplyItemEntity item : entityItems) {
				items.add(item.toEntity());
			}
		}
		toEntity.setItems(items);
		return toEntity;
	}

	@Override
	public void setId(String arg0) {
		this.setApplyID(arg0);
	}
}
